package com.example.textview;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;


import com.example.textview.MediaPlay.MymediaPlayActivity;
import com.example.textview.datastorage.DataStorageActivity;
import com.example.textview.frament.ContainerActivity;
import com.example.textview.gridview.GridViewActivity;
import com.example.textview.listview.ListviewActivity;
import com.example.textview.recycleview.RecycleActivity;
import com.example.textview.util.ToastUtil;

public class MainActivity extends AppCompatActivity {

    private Button btn_TextView;
    private Button mButton;
    private Button mbtn_Edite;
    private Button mbtn_Radiobutton,mbtn_checbox,mbtn_Imageview,mbtn_listview,mbtn_gridview,mbtn_camera,mbtn_RecycleView;

    private  Button mbtn_Webview,mbtn_dialog,mbtn_progress,mbtn_CustomDialog,mbtn_fragment,mbtn_toobar,mbtn_handler;
    private Button mbtn_datastorage ,mbtn_speech ,mbtn_newCamera,mbtn_tcp,mbtn_location, mbtn_imageSelcet,mbtn_video,mbtn_PLC;

    Button mbtn_emagetouch,mbtn_air;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_TextView=findViewById(R.id.btn_textView);
        btn_TextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到TextVIEW演示界面

                Intent intent=new Intent(MainActivity.this,TextViewActivity.class);
                Bundle bundle =new Bundle();
                bundle.putString("name","sky");
                bundle.putDouble("age",10.3);
                intent.putExtras(bundle);
               // startActivity(intent);
                startActivityForResult(intent,0);
                Log.d("qqq","this");
            }
        });

        mButton=findViewById(R.id.btn_button1);
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            //跳转到bUTTON演示界面
                Intent intent=new Intent(MainActivity.this,ButtonActivity.class);
                startActivity(intent);
            }
        });

        mbtn_Edite=findViewById(R.id.btn_edittext);
        mbtn_Edite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到Editext演示界面
                Intent intent=new Intent(MainActivity.this,EditTextActivity.class);
                startActivity(intent);
            }
        });



        mbtn_Radiobutton=findViewById(R.id.btn_Radiobutton);
        mbtn_checbox=findViewById(R.id.btn_checbox);
        mbtn_Imageview=findViewById(R.id.btn_imageview);
        mbtn_listview=findViewById(R.id.btn_listview);
        mbtn_gridview=findViewById(R.id.btn_gridciew);
        mbtn_camera=findViewById(R.id.btn_camera);
        mbtn_RecycleView=findViewById(R.id.btn_Recyclerview);
        mbtn_Webview=findViewById(R.id.btn_WebView);
        mbtn_dialog= findViewById(R.id.btn_Dialog);
        mbtn_progress=findViewById(R.id.btn_ProcessBar);
        mbtn_CustomDialog=findViewById(R.id.btn_CustomDialog);
        mbtn_fragment=findViewById(R.id.btn_fragment);
        mbtn_toobar=findViewById(R.id.btn_toobar);
        mbtn_handler=findViewById(R.id.btn_handler);
        mbtn_datastorage=findViewById(R.id.btn_datastorage);
        mbtn_speech=findViewById(R.id.btn_speech);
        mbtn_newCamera=findViewById(R.id.btn_newCamera);
        mbtn_tcp=findViewById(R.id.btn_tcp);

        mbtn_location=findViewById(R.id.btn_location);
        mbtn_video=findViewById(R.id.btn_video);

        mbtn_imageSelcet=findViewById(R.id.btn_imageSelcet);

        mbtn_PLC=findViewById(R.id.btn_PLC);

        mbtn_emagetouch=findViewById(R.id.btn_emagetouch);
        mbtn_air=findViewById(R.id.btn_air);
        setListener();
        //Manifest.permission.WRITE_EXTERNAL_STORAGE

//        ActivityCompat.requestDragAndDropPermissions(this,new String[]{
//                permission.WRITE_EXTERNAL_STORAGE},1);
    }

    private void setListener(){
        onClick onclick=new onClick();
        mbtn_Radiobutton.setOnClickListener(onclick); //新的测试  注册方法
        //mbtn_Edite.setOnClickListener(onclick);
        mbtn_checbox.setOnClickListener(onclick); //新的测试  注册方法
        mbtn_Imageview.setOnClickListener(onclick); //新的测试  注册方法
        mbtn_listview.setOnClickListener(onclick); //新的测试  注册方法
        mbtn_gridview.setOnClickListener(onclick);
        mbtn_camera.setOnClickListener(onclick);
        mbtn_RecycleView.setOnClickListener(onclick);
        mbtn_Webview.setOnClickListener(onclick);
        mbtn_dialog.setOnClickListener(onclick);
        mbtn_progress.setOnClickListener(onclick);
        mbtn_CustomDialog.setOnClickListener(onclick);
        mbtn_fragment.setOnClickListener(onclick);
        mbtn_toobar.setOnClickListener(onclick);
        mbtn_handler.setOnClickListener(onclick);
        mbtn_datastorage.setOnClickListener(onclick);
        mbtn_speech.setOnClickListener(onclick);
        mbtn_newCamera.setOnClickListener(onclick);
        mbtn_tcp.setOnClickListener(onclick);
        mbtn_location.setOnClickListener(onclick);
        mbtn_imageSelcet.setOnClickListener(onclick);
        mbtn_video.setOnClickListener(onclick);
        mbtn_PLC.setOnClickListener(onclick);
        mbtn_emagetouch.setOnClickListener(onclick);
        mbtn_air.setOnClickListener(onclick);
    }

    private class onClick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            Intent intent=null;
            switch (view.getId())
            {
                case R.id.btn_textView :
                    intent=new Intent(MainActivity.this,TextViewActivity.class);
                    Bundle bundle =new Bundle();
                    bundle.putString("name","sky");
                    bundle.putDouble("age",10.3);
                    intent.putExtras(bundle);
                    break;

                case R.id.btn_button1 :
                    intent=new Intent(MainActivity.this,ButtonActivity.class);
                    break;

                case R.id.btn_edittext :
                    intent=new Intent(MainActivity.this,EditTextActivity.class);
                    break;


                case R.id.btn_Radiobutton :
                    intent=new Intent(MainActivity.this,RadioActivity.class);
                    break;


                case R.id.btn_checbox :
                    intent=new Intent(MainActivity.this,CheckBoxActivity.class);
                    break;
                case R.id.btn_imageview:
                intent=new Intent(MainActivity.this,ImageViewActivity.class);
                break;

                case R.id.btn_listview:
                    intent=new Intent(MainActivity.this, ListviewActivity.class);
                    break;


                case R.id.btn_gridciew:
                    intent=new Intent(MainActivity.this, GridViewActivity.class);
                    break;


                case R.id.btn_camera:
                    intent=new Intent(MainActivity.this, CameraActivity.class);
                    break;
                case R.id.btn_Recyclerview:
                    intent=new Intent(MainActivity.this, RecycleActivity.class);
                    break;

                case R.id.btn_WebView:
                    intent=new Intent(MainActivity.this, WebViewActivity.class);
                    break;

                case R.id.btn_Dialog:
                    intent=new Intent(MainActivity.this, DialogActivity.class);
                    break;
                case R.id.btn_ProcessBar:
                    intent=new Intent(MainActivity.this, ProgressActivity.class);
                    break;


                case R.id.btn_CustomDialog:
                    intent=new Intent(MainActivity.this, CustomDialgActivity.class);
                    break;
                case R.id.btn_fragment:
                    intent=new Intent(MainActivity.this, ContainerActivity.class);
                    break;
                case R.id.btn_toobar:
                    intent=new Intent(MainActivity.this, ToobarActivity.class);
                    break;

                case R.id.btn_handler:
                    intent=new Intent(MainActivity.this, HandlerActivity.class);
                    break;

                case R.id.btn_datastorage:
                    intent=new Intent(MainActivity.this, DataStorageActivity.class);
                    break;


                case R.id.btn_speech:

                    intent=new Intent(MainActivity.this, TextToSpeechActivity.class);
                    break;

                case R.id.btn_newCamera:

                    intent=new Intent(MainActivity.this, CameraNewActivity.class);
                    break;

                case R.id.btn_tcp:

                    intent=new Intent(MainActivity.this, TcpActivity.class);
                    break;

                case R.id.btn_location:

                    intent=new Intent(MainActivity.this, LocationActivity.class);
                    break;


                case R.id.btn_imageSelcet:
                    intent=new Intent(MainActivity.this, ImageSelcetActivity.class);
                    break;

                case R.id.btn_video:
                    intent=new Intent(MainActivity.this, MymediaPlayActivity.class);
                    break;

                case R.id.btn_PLC:
                    intent=new Intent(MainActivity.this, Plctcp.class);
                    break;

                case R.id.btn_emagetouch:
                    intent=new Intent(MainActivity.this, ImagTouchActivity.class);
                    break;

                case R.id.btn_air:
                    intent=new Intent(MainActivity.this, AirAPIActivity.class);
                    break;


            }


            startActivity(intent);

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d("TEST","onActivityResult");

        if(requestCode==0)
        {
            Log.d("TEST","requestCode"+requestCode);

            if(data!=null){
            Bundle bundle=data.getExtras();
            if(bundle!=null){
            String SS=bundle.getString("www");
            ToastUtil.showMsg(this,SS);
            }}
        }
    }
}